﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AbstraX.ServerInterfaces;
using System.Diagnostics;
using CodeGenerationPipeline.Contracts;

namespace CodeGenerationPipeline
{
    [DebuggerDisplay(" { DebugInfo } ")]
    public class NavigationItem
    {
        public object NavigationProperty { get; set; }
        public IElement NavigationResultElement { get; private set; }
        public IElementBuild NavigationResultBuild { get; set; }

        public NavigationItem(IElement navigationProperty, IElement navigationResultElement)
        {
            this.NavigationProperty = navigationProperty;
            this.NavigationResultElement = navigationResultElement;
        }

        public NavigationItem(string navigationPropertyName, IElement navigationResultElement)
        {
            this.NavigationProperty = navigationPropertyName;
            this.NavigationResultElement = navigationResultElement;
        }

        public string PropertyName
        {
            get
            {
                if (this.NavigationProperty is string)
                {
                    return (string)(object) this.NavigationProperty;
                }
                else
                {
                    return ((IElement)this.NavigationProperty).Name;
                }
            }
        }

        public string DebugInfo
        {
            get
            {
                return string.Format("Property='{0}' returns type: '{1}'", this.PropertyName, this.NavigationResultBuild.Element.DataType.FullyQualifiedName);
            }
        }
    }
}
